package com.pactera.elasticsearch.service;

import com.pactera.elasticsearch.bean.Index;
import com.pactera.elasticsearch.bean.Search;
import com.pactera.elasticsearch.commons.Elasticsearch;
import com.pactera.elasticsearch.commons.Page;

import java.io.IOException;
import java.util.List;

/**
 * @author: liqingdian
 **/
public interface ElasticService {

    /**
     * 初始化索引
     *
     * @author: liqingdian
     */
    void initIndex() throws IOException;

    /**
     * 索引列表
     *
     * @author: liqingdian
     */
    List<Index> indices() throws IOException;

    /**
     * 新增/更新索引数据
     *
     * @param document 文档
     * @param async    是否异步
     * @author: liqingdian
     */
    void save(Elasticsearch document, boolean async) throws IOException;

    /**
     * 删除文档
     *
     * @param index 索引
     * @param guid  唯一标识
     * @author: liqingdian
     */
    void delete(String index, String guid) throws IOException;

    /**
     * 文档详情
     *
     * @param guid  唯一标识
     * @param clazz 类型
     * @author: liqingdian
     */
    <T extends Elasticsearch> T info(String guid, Class<T> clazz) throws IOException;

    /**
     * 分页查询
     *
     * @param search 查询条件
     * @param clazz 类型
     * @author: liqingdian
     */
    <T extends Elasticsearch> Page<T> pages(Search search, Class<T> clazz) throws IOException;
}
